package cn.itcast.service.impl;

import cn.itcast.annotation.AddAnnotation;
import cn.itcast.annotation.UpdateAnnotation;
import cn.itcast.mapper.ClazzMapper;
import cn.itcast.pojo.*;
import cn.itcast.service.ClazzService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    @AddAnnotation
    public boolean addClazz(Clazz clazz) {
        int row = clazzMapper.addClazz(clazz);
        return row > 0;
    }

    @Override
    public ClazzById findById(Integer id) {
        ClazzById clazzById = clazzMapper.findById(id);
        return clazzById;
    }

    @Override
    @UpdateAnnotation
    public boolean updateClazz(Clazz clazz) {
        int row = clazzMapper.updateClazz(clazz);
        return row > 0;
    }

    @Override
    public ClazzBean studentCountData() {
        List<ClazzGroup> clazzGroups = clazzMapper.studentCountData();
        if (clazzGroups != null && clazzGroups.size() > 0) {
            ClazzBean clazzBean = new ClazzBean();
            for (ClazzGroup clazzGroup : clazzGroups) {
                clazzBean.getClazzList().add(clazzGroup.getClazzName());
                clazzBean.getDataList().add(clazzGroup.getClazzCount());
            }
            return clazzBean;
        }
        return null;
    }

    @Override
    public List<Clazz> findAllClazz() {
        List<Clazz> list = clazzMapper.findAllClazz();
        return list;
    }

    @Override
    public PageBean<Clazz> findByColClazz(String name, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {
        return null;
    }

    /*@Override
    public PageBean<Clazz> findByColClazz(String name, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Clazz> clazzs = clazzMapper.findByColClazz(name, begin, end);
        Page<Clazz> p = (Page<Clazz>) clazzs;
        PageBean<Clazz> pageBean = new PageBean<>((int) p.getTotal(), clazzs);
        return pageBean;
    }*/

    @Override
    public boolean deleteById(Integer id) {
        int row = clazzMapper.deleteById(id);
        return row > 0;
    }
}
